package com.agri.mapper;

import com.agri.entity.Crop;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 农产品Mapper接口
 * 提供农产品数据的CRUD操作
 *
 * @author Agri-Fin-Sale Team
 * @since 2025-10-31
 */
@Mapper
public interface CropMapper extends BaseMapper<Crop> {

    /**
     * 根据分类ID查询农产品列表
     * @param categoryId 分类ID
     * @return 农产品列表
     */
    @Select("SELECT * FROM t_crop WHERE category_id = #{categoryId} AND status = 1 ORDER BY crop_code")
    List<Crop> selectByCategoryId(@Param("categoryId") Long categoryId);



    /**
     * 根据农产品编码查询农产品信息
     * @param cropCode 农产品编码
     * @return 农产品信息
     */
    @Select("SELECT * FROM t_crop WHERE crop_code = #{cropCode} AND status = 1")
    Crop selectByCropCode(@Param("cropCode") String cropCode);

    /**
     * 根据分类编码查询农产品列表
     * @param categoryCode 分类编码
     * @return 农产品列表
     */
    @Select("SELECT c.* FROM t_crop c " +
            "INNER JOIN t_crop_category cc ON c.category_id = cc.id " +
            "WHERE cc.category_code = #{categoryCode} AND c.status = 1 " +
            "ORDER BY c.crop_code")
    List<Crop> selectByCategoryCode(@Param("categoryCode") String categoryCode);

    /**
     * 查询所有启用的农产品
     * @return 农产品列表
     */
    @Select("SELECT * FROM t_crop WHERE status = 1 ORDER BY category_id, crop_code")
    List<Crop> selectAllEnabled();
}